package com.yihuier.yihuier.Service.UserManager;

import com.yihuier.yihuier.Mapper.UserManager.DepartmentUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class DepartmentUserService {

    @Autowired
    private DepartmentUserMapper departmentUserMapper;

    /**
     * 根据部门编号获取该部门所有用户编号
     * @param department_id 部门编号
     * @return
     */
    public ArrayList<Integer> getUsersByDepartmentId(int department_id){return departmentUserMapper.selectUsersByDepartmentId(department_id);}

    /**
     * 通过用户编号获取用户部门编号
     * @param user_id 用户编号
     * @return 用户所属部门号
     */
    public int getDepartmentIdByUserId(int user_id) {
        return departmentUserMapper.selectDepartmentIdByUserid(user_id);
    }

    /**
     * 得到某部门的总人数（包括已删除的）
     * */
    public int getSumOfUsersInDepartment(int department_id){
        return departmentUserMapper.selectSumOfUsersInDepartment(department_id);
    }

    /**
     * 管理员添加新用户，再部门用户表中添加信息
     * */
    public int addDepartmentUser(int department_id,int user_id){
        return departmentUserMapper.insertDepartmentUser(department_id,user_id);
    }
}
